//
//  ZYXRecommendViewController.m
//  RuiBeiKang
//
//  Created by 代码女神 on 2019/1/9.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXRecommendViewController.h"
#import "ZYXShareView.h"


#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
@interface ZYXRecommendViewController ()<ZYXShareViewDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *qrcodeImgView;

/** 分享界面 */
@property (strong, nonatomic) ZYXShareView *shareView;

@end

@implementation ZYXRecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"推荐好友";
    [self.view addSubview:self.shareView];
    
    
    [self.qrcodeImgView sd_setImageWithURL:[NSURL URLWithString:kInterfaceAllUrl(@"/Public/Uploads/tupian/qrcode.jpg")] placeholderImage:IMG(@"imgLoading")];
    
}

- (IBAction)shareAction:(UIButton *)sender {
    self.shareView.hidden = NO;
    
    
}
#pragma mark ZYXShareViewDelegate
-(void)clickZYXShareViewBtn:(NSInteger)index{
    //创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"知与行"
                                     images:IMG(@"guanyuwomen-1")
                                        url:[NSURL URLWithString:kInterfaceAllUrl(PATH_WDShareQcode)]
                                      title:@"知与行"
                                       type:SSDKContentTypeAuto];
    if (index == 1000) {
        
       //分享到朋友圈
        //进行分享
        [ShareSDK share:SSDKPlatformSubTypeWechatTimeline //传入分享的平台类型
             parameters:shareParams
         onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....
             NSString *titleStr = @"";
             switch (state) {
                 case SSDKResponseStateSuccess:{
                     titleStr = @"分享成功";
                     break;
                 }
                 case SSDKResponseStateFail:{
                     titleStr = @"分享失败";
                     break;
                 }
                 default:
                     titleStr = @"分享失败";
                     break;
             }
             UIAlertController *ctrl = [UIAlertController alertControllerWithTitle:titleStr message:nil preferredStyle:UIAlertControllerStyleAlert];
             [ctrl addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

             }]];
         }];
    }else{
       //分享给朋友
        [ShareSDK share:SSDKPlatformSubTypeWechatSession //传入分享的平台类型
             parameters:shareParams
         onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....
             NSString *titleStr = @"";
             switch (state) {
                 case SSDKResponseStateSuccess:{
                     titleStr = @"分享成功";
                     break;
                 }
                 case SSDKResponseStateFail:{
                     titleStr = @"分享失败";
                     break;
                 }
                 default:
                     titleStr = @"分享失败";
                     break;
             }
             UIAlertController *ctrl = [UIAlertController alertControllerWithTitle:titleStr message:nil preferredStyle:UIAlertControllerStyleAlert];
             [ctrl addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                 
             }]];
         }];
    }
}
#pragma mark 懒加载
- (ZYXShareView *)shareView{
    if (!_shareView){
        _shareView = [[NSBundle mainBundle] loadNibNamed:@"ZYXShareView" owner:nil options:nil].lastObject;
        _shareView.frame = self.view.bounds;
        _shareView.hidden = YES;
        _shareView.delegate = self;
    }
    return _shareView;
}

@end
